package com.syn.syn1;

import org.apache.catalina.Executor;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Auther: zch
 * @Date: 2019/1/8 08:42
 * @Description:
 */
public class ThreadPoolDemo {
    public static void main(String[] args) throws InterruptedException {

        MyTask task = new MyTask();
        ExecutorService executorService = Executors.newFixedThreadPool(5);

        for (int i=0;i<10;i++) {
            executorService.submit(task);
        }

    }

    public static class MyTask implements Runnable {
        @Override
        public void run() {
            System.out.println(System.currentTimeMillis() + ":thread ID:" + Thread.currentThread().getId());

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
    }
}

